/**
 * 
 */
package org.paybiz.core.payplatform.bill99.service;

import java.util.Date;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.paybiz.constant.PayConstant;
import org.paybiz.core.payplatform.bill99.entity.Ivr;
import org.paybiz.core.payplatform.bill99.entity.ResultVO;
import org.paybiz.core.service.pay.PayService;
import org.paybiz.model.PayModel;
import org.paybiz.model.PayReqResultDO;
import org.paybiz.util.OprateHelper;
import org.paybiz.util.PaySignUtil;
import org.paybiz.util.TranslateUtil;
import org.springframework.stereotype.Service;

/**
 * 语音支付
 * @author nassir wen
 * @data 2012-5-18 下午05:28:54
 * @version V2.5
 * @Company: MSD.
 * @Copyright Copyright (c) 2012
 */
@Service("ivrPayService")
public class IvrPayServiceImpl implements PayService {
    private final static Log logger = LogFactory
            .getLog(IvrPayServiceImpl.class);

    /**
     * 订单支付
     */
    @Override
    public PayReqResultDO pay(PayModel payDO) {
        logger.info("语音支付");
        Ivr ivr = new Ivr();
        String amount = TranslateUtil.getFen2Yuan(payDO.getPayMoney());
        // 卡号
       /* ivr.setCardNo(payDO.getIvrPay().getBankCardNo());
        // 金额，元为单位
        ivr.setAmount(amount);
        // 终端编号
        ivr.setTerminalId(ConstantBill99Util.TERMINALID);
        // 交易时间:yyyyMMddHHmmss
        ivr.setEntryTime(DateUtil.convertDateToString(new Date()));
        // 身份证
        ivr.setCardHolderId(payDO.getIvrPay().getCardId());
        // 真实姓名
        ivr.setCardHolderName(payDO.getIvrPay().getRealName());
        // 手机号
        ivr.setCellphone(payDO.getIvrPay().getMobilePhone());
        // 订单号
        ivr.setExternalRefNumber(payDO.getOrderId());*/
        ResultVO result = IvrServiceHandler.ivrSend(ivr);
        PayReqResultDO payReqResult = new PayReqResultDO();
        if (StringUtils.equals(result.getResultCode(), PayConstant.RESULT_SUCCESS
                + "")) {
            payReqResult.setResult(PayConstant.RESULT_SUCCESS);
        } else {
            payReqResult.setResult(PayConstant.RESULT_FAIL);
            payReqResult.setErrId(result.getResultCode());
            payReqResult.setErrMsg(result.getErrMsg());
        }
        payReqResult.setHmac(PaySignUtil.getComObjSign(payReqResult,
                OprateHelper.msdKey));
        return payReqResult;
    }

    @Override
    public int autoCheckOrder(String orderId, Date date, Integer tag) {
        return 0;
    }
}
